package il.ac.technion.wiki.api;

import java.util.SortedMap;

import il.ac.technion.wiki.api.IContentImporter;
import il.ac.technion.wiki.api.IContentImporter.ContentException;
import il.ac.technion.wiki.api.IDataStore.DataStoreException;
import il.ac.technion.wiki.api.IDataStore.NotFoundException;
import il.ac.technion.wiki.api.search.ISearchExpression;
import il.ac.technion.wiki.api.support.queries.QueryParser;
import il.ac.technion.wiki.api.support.queries.QueryParser.IllegalQueryException;
import il.ac.technion.wiki.impl.WikiEngine.WikiContent;

/**
 * Defines the interface for the wiki engine.
 */
public abstract class AbstractWikiEngine implements IWikiEngine {
	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#importContent(byte[], java.lang.String)
	 */
	@Override
	public abstract WikiContent importContent(byte[] content, String contentType, String name) throws ContentException;

	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#removeImporter(java.lang.String)
	 */
	@Override
	public abstract void removeImporter(String contentType);
	
	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#addImporter(il.ac.technion.wiki.api.IContentImporter)
	 */
	@Override
	public abstract void addImporter(IContentImporter importer);
	
	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#addNeutralWord(java.lang.String)
	 */
	@Override
	public abstract void addNeutralWord(String word);
	
	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#removeNeutralWord(java.lang.String)
	 */
	@Override
	public abstract void removeNeutralWord(String word);
	
	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#getNeutralWords()
	 */
	@Override
	public abstract String[] getNeutralWords();
	
	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#get(java.lang.String)
	 */
	@Override
	public  abstract IWikiEngine.IWikiContent get(String name) throws NotFoundException, DataStoreException;
	
	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#search(java.lang.String)
	 */
	@Override
	public SortedMap<Integer, WikiContent> search(String expr) throws DataStoreException, BadQueryException{
		try {
			return search(QueryParser.parse(expr));
		} catch (IllegalQueryException e) {
			throw new BadQueryException();
		}
	}
	
	protected abstract SortedMap<Integer, WikiContent> search(ISearchExpression expr) throws DataStoreException, BadQueryException;

	
	/* (non-Javadoc)
	 * @see il.ac.technion.wiki.api.IWikiEngine#setRanker(il.ac.technion.wiki.api.IContentRanker)
	 */
	@Override
	public abstract void setRanker(IContentRanker ranker);
	
	
}
